<template>
  <!-- 安检通道综合效率 -->
  <div class="content-app">
    <div class="up">
      <SecurityCheckHeader
        title="安检通道过检效率"
        :withExportButton="false"
        :withChangeButton="false"
        @search="search"
      />
    </div>
    <div class="comprehensive">
      <div class="header">
        <p>过检效率 - 综合风险等级</p>
        <span>单位：件</span>
      </div>
      <div class="comprehensive_cont">
        <div id="comprehensiveCharts"></div>
      </div>
    </div>
  </div>
</template>
<script>
import { eleCake } from '@/utils/app-ecahrts'
import SecurityCheckHeader from '../components/securityCheckHeader.vue'
import { correlation } from '@/api/statistics/statistics.js'
export default {
  data() {
    return {
      queryData: {},
    }
  },
  components: {
    SecurityCheckHeader,
  },
  mounted() {
    // this.relationDate();
  },
  methods: {
    search(data) {
      this.queryData = {
        startTime: data[0][0],
        endTime: data[0][1],
        levelId: '',
        proxyLevel: data[1],
        proxyId: data[2],
      }
      this.relationDate(data)
    },
    //点击跳转
    echar() {
      // this.$router.push({
      //   path: "/securityCheck/waybillTable",
      //   query: this.queryData,
      // });
    },
    change() {
      this.$router.push('./agentTable')
    },
    up(x, y) {
      return parseInt(x.channel.slice(1)) - parseInt(y.channel.slice(1))
    },
    async relationDate(data) {
      try {
        let params = {
          beginDate: data[0][0],
          endDate: data[0][1],
          proxyLevel: data[1],
          levelId: '',
          proxyId: data[2],
        }
        const result = await correlation(params)
        result.data.sort(this.up)
        if (result.status == 200) {
          let arr = [] //高风险
          let Low = [] //低风险
          let firs = [] //优先级
          let pt = []
          let strictly = []
          let arrx = [] //x轴
          result.data.forEach((element) => {
            arrx.push(element.channel)
            element.datas.forEach((res) => {
              if (res.level === '高风险') {
                arr.push(res.count)
              } else if (res.level == '低风险') {
                Low.push(res.count)
              } else if (res.level == '优先') {
                firs.push(res.count)
              } else if (res.level == '普通') {
                pt.push(res.count)
              } else if (res.level == '严控') {
                strictly.push(res.count)
              }
            })
            // console.log(arr);
          })
          let datas = []
          for (let i = 0; i <= arr.length; i++) {
            datas[i] = arr[i] + Low[i] + firs[i] + pt[i] + strictly[i]
          }
          this.init(arr, arrx, Low, firs, pt, strictly, datas)
        }
      } catch (error) {
        console.log(error)
      }
    },
    init(arr, arrx, Low, firs, pt, strictly, datas) {
      let myChart = this.$echarts.init(document.getElementById('comprehensiveCharts')) //统计折线
      eleCake.series[0].data = arr
      eleCake.series[1].data = Low
      eleCake.series[2].data = firs
      eleCake.series[3].data = pt
      eleCake.series[4].data = strictly
      eleCake.series[5].data = datas
      eleCake.xAxis.data = arrx
      myChart.clear()
      myChart.setOption(eleCake, true)
      window.onresize = () => {
        myChart.resize()
      }
      myChart.on('click', (a, b) => {
        this.queryData.riskRating = a.seriesName
        // this.queryData.openResult = a.value;
        this.echar()
      })
    },
  },
}
</script>
<style lang="scss" scoped>
.up {
  padding-top: 12px;
}
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  > p {
    font-size: 18px;
    font-family: Microsoft YaHei;
    font-weight: bold;
    color: #101116;
    margin: 0 0 24px 0;
  }
  > span {
    font-size: 14px;
    font-family: Microsoft YaHei;
    font-weight: 400;
    color: #101116;
  }
}
.comprehensive {
  width: 100%;
  height: 77vh;
  padding: 24px;
  background: #ffffff;
  box-shadow: 0px 3px 10px 0px rgba(0, 0, 0, 0.1);
  border-radius: 4px;
  > .comprehensive_cont {
    width: 100%;
    height: 95%;
    #comprehensiveCharts {
      width: 100%;
      height: 100%;
    }
  }
}
</style>